﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Autofac;
using Autofac.Builder;
using Autofac.Core;
using Autofac.Util;
using Autofac.Features;
using System.Collections.Concurrent;
using System.Reflection;
using System.Security.Cryptography;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Web;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string data = @"区***路','maritalStatus':'01','education':'03','city':'北京','address':'山东省济南市高新区***路','name':'张三','age':'23','mortgageState':'01','houseProperty':'Y','mobileNumber':'1366****123','applyAmount':'500','loanTerm':'24'";
            // string data = "asdfasd";
            //var result = rsa.RSAEncrypt(data, rsa._publicKeyRsaProvider);
            // data = HttpUtility.UrlEncode(data);

            //data= @"{'name':'ho**8ngda','age':31}";
            //data= @"{'source':'DFRZW','applyLoanList':[{'name':'dsfg','age':'33','sex':'01','mobileNumber':'11111111111','applyAmount':3,'loanTerm':12,'city':'上海市','houseProperty':'Y'}]}";
            //data = @"{'source':'DFRZW','applyLoanList':{'name':'dsfg','age':'33','sex':'01'";
            Console.WriteLine(data.Length);
            //string pubkey = GetAppSettings("pubkey");
            //string prikey = GetAppSettings("prikey");

            string pubkey = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCYMTaH4NMw5fQsgx3pv8xaAxhO
dtUz/m5nfl9XHtGboXNzUzx/ehh8c3RgpGcig83JXOYOXafmx3OS28Ed3e2fmC5Y
o5RD6DRHnBCid28EjQ5PgCTddNqDvcXU3YMH4sO1qNBx5MQpk92Kt/NdquIJmzhg
pjP15MO5CFHcU90ZvQIDAQAB";
            string prikey = @"MIICWwIBAAKBgQCYMTaH4NMw5fQsgx3pv8xaAxhOdtUz/m5nfl9XHtGboXNzUzx/
ehh8c3RgpGcig83JXOYOXafmx3OS28Ed3e2fmC5Yo5RD6DRHnBCid28EjQ5PgCTd
dNqDvcXU3YMH4sO1qNBx5MQpk92Kt/NdquIJmzhgpjP15MO5CFHcU90ZvQIDAQAB
AoGANlvdjkrPI/f+bqemV4caBkx0shHftOJ7rJuGkid/1oakJdzlDuMdO9ZBCwOt
krZhGjsEML1i6xryPNIg9/n8lSdQqIUW61HXYwKUK5xQWz/MstWbbIx3t5driQFR
Fv53NLdemeF/0AJiD5COO1fkoM+1By2LlI0ths8cQLcOpgECQQDIc46yV1N5IuS0
MYD0LgggaJ08WF0PrwjXgs+DRp3+ZE5WTs1JDkBQM9E598xbmy7AAFtdtR3L5CH8
5Qh+KfwJAkEAwl4MuRMdIjiHiw1YoIUliy6t3XPvxeOEiG/P15adKrxI5A5QylM0
TtbZT3YZurdy3nrJ75LxuU9cSYKzxtVFFQJAMboJElD7kjeHyPPm66xns7KAHzJE
k9l2NhBrbkOcejlj/aE65/6zEbJpGxpQBgGvTU5JXCvMIoKLs/MVckb0EQJASze+
ULkW4zFhMuy9SZF9T/mGi1bciYZcubgbhODifbFTu/3WQhYk/gWjH18i4eEwcOyv
zSjepsoRetk73UyXaQJAOfr3Gg1dGvoLiwZ3fXoDVupahnKg73SAd72+24qQs2AT
16T8FKop259xisLu+WSUTfSUhao5qOpZJ/PTwFRlzw==";

            RSACryptoServiceHelper helper = new RSACryptoServiceHelper(prikey, pubkey);
            //string json = helper.RSAEncrypt(data, helper._publicKeyRsaProvider);
            //string json2 = helper.RSADecrypt(json, helper._privateKeyRsaProvider);

            //string json = helper.RSASectionEncrypt(data, helper._publicKeyRsaProvider);
            //string json2 = helper.RSASectionDecrypt(json, helper._privateKeyRsaProvider);

            string json = helper.RSASectionEncrypt(data, helper._privateKeyRsaProvider);
            string json2 = helper.RSASectionDecrypt(json, helper._publicKeyRsaProvider);
            Console.WriteLine(json);
            Console.WriteLine(json2);

            string result = string.Empty;
            //helper.SignatureFormatterSHA1(prikey, data, ref result);
           

            helper.SignatureFormatter(data, helper._privateKeyRsaProvider, ref result); 
            Console.WriteLine(result);
            Console.ReadLine();
        }

        public static string GetAppSettings(string SettingName)
        {
            try
            {
                string _result = System.Configuration.ConfigurationManager.AppSettings[SettingName].ToString();
                return _result;
            }
            catch (Exception ex)
            {
              
                return "";
            }

        }
    }
}
